﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;

namespace WCFServerGUI
{
    public partial class WCFServerGUI : Form
    {

        ServiceHost host_lobby;
        ServiceHost host_room;
        

        bool started;

        public WCFServerGUI()
        {
            InitializeComponent();
            host_lobby = new ServiceHost(typeof(WCFGameService.LobbyService));
            host_room = new ServiceHost(typeof(WCFGameService.RoomService));

            this.started = false;
            this.toolStripProgressBar1.AutoSize = true;
            this.toolStripProgressBar1.Minimum = 0;
            this.toolStripProgressBar1.Maximum = 3;
            this.toolStripProgressBar1.Value = 0;
        }

        private void SratStopButton_Click(object sender, EventArgs e)
        {
            if (!this.started)
            {
                this.ActionsText.Text += "creating host for lobby services...\n";
                this.toolStripProgressBar1.Value = 1;
                host_lobby.Open();
                this.ActionsText.Text += "lobby services host in now online\n";
                this.ActionsText.Text += "***********************************\n";
                this.ActionsText.Text += "creating host for room services...\n";
                this.toolStripProgressBar1.Value = 2;
                host_room.Open();
                this.ActionsText.Text += "room services host in now online\n";
                this.ActionsText.Text += "***********************************\n";
                
                this.toolStripProgressBar1.Value = 3;
 
                this.started = true;
                this.SratStopButton.Text = "Stop";
                this.statusLabel.Text = "online";
            }
            else
            {
                this.ActionsText.Text += "closing host for lobby services...\n";
                this.toolStripProgressBar1.Value = 1;
                host_lobby.Close();
                this.ActionsText.Text += "lobby services host in now offline\n";
                this.ActionsText.Text += "***********************************\n";
                this.ActionsText.Text += "closing host for room services...\n";
                this.toolStripProgressBar1.Value = 2;
                host_room.Close();
                this.ActionsText.Text += "room services host in now offline\n";
                this.ActionsText.Text += "***********************************\n";
 
                this.started = false;
                this.SratStopButton.Text = "Start";
                this.statusLabel.Text = "offline";
                host_lobby = new ServiceHost(typeof(WCFGameService.LobbyService));
                host_room = new ServiceHost(typeof(WCFGameService.RoomService));
 
            }

        }
    }
}
